// part1:C11:ex11.31.cpp
// define a multimap about author's name and composer.
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

void remove_author(multimap<string, string> &books, const string &author)
{
  auto pos = books.equal_range(author);
  if (pos.first == pos.second)
    cout << "No " << author << endl;
  else
    books.erase(pos.first, pos.second);
}

void print_books(multimap<string, string> &books)
{
  cout << "current catagories include :" << endl;
  for (auto &book : books)
  {
    cout << book.first << ", (" << book.second << ")" << endl;
  }
  cout << endl;
}

int main(int argc, char *argv[])
{
  multimap<string, string> books;
  books.insert({"Barth John", "Sot-Weed Factor"});
  books.insert({"Barth John", "Lost in the Funhouse"});
  books.insert({"Linton", "Weed World"});
  books.insert({"Harmilton", "Real myself"});

  print_books(books);
  remove_author(books, "Zhang");

  remove_author(books, "Barth John");
  print_books(books);

  return 0;
}
